package com.swjd;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author 刘涛
 * @create 2021/10/9 12:08
 */
@Controller
public class UserController {
    @Autowired
    private UserDao userDao;
    @Autowired
    private MessageDao messageDao;
    @RequestMapping("/findUserList")
    public String a(Model model){
        List<User> users = userDao.selectList(null);
        model.addAttribute("users",users);
        return "manageUser";
    }
    @RequestMapping("/addUser")
    public String b(){
        return "addUser";
    }
    @RequestMapping("insert")
    public String c(String nicheng,String truename,String cardid,String email,String telephone,String qq){
        User user = new User();
        user.setName(nicheng);
        user.setTruename(truename);
        user.setCardid(cardid);
        user.setEmail(email);
        user.setTelephone(telephone);
        user.setPwd(qq);
        userDao.insert(user);
        return "redirect:/findUserList";
    }
    @RequestMapping("/del/{id}")
    public String del(@PathVariable Integer id){
        userDao.deleteById(id);
        return "redirect:/findUserList";
    }
    @RequestMapping("/manageLeaveword")
    public String manageLeaveword(Model model){
        List<Message> messages = messageDao.selectList(null);
        model.addAttribute("messages",messages);
        return "manageLeaveword";
    }
    @RequestMapping("/editLeaveword/{id}")
    public String editLeaveword(Model model,@PathVariable Integer id){
        Message message = messageDao.selectById(id);
        model.addAttribute("message",message);
        return "editLeaveword";
    }
    @RequestMapping("/delMessage/{id}")
    public String delMessage(@PathVariable Integer id){
        messageDao.deleteById(id);
        return "redirect:/manageLeaveword";
    }
}
